﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Aliyeye.Car.Net.Utility;
using System.Data.SqlClient;

namespace Aliyeye.Car.Net.Dal
{
    public class PageData
    {
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(Model.PageData value)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@Tables", SqlDbType.VarChar, 3000),
                    new SqlParameter("@PrimaryKey" , SqlDbType.VarChar , 500),    
                    new SqlParameter("@Sort", SqlDbType.VarChar , 500 ),
                    new SqlParameter("@CurrentPage", SqlDbType.Int),
                    new SqlParameter("@PageSize", SqlDbType.Int),                                    
                    new SqlParameter("@Fields", SqlDbType.VarChar, 4000),
                    new SqlParameter("@Filter", SqlDbType.VarChar,1000),
                    new SqlParameter("@Group" ,SqlDbType.VarChar , 1000 )
                    };
            parameters[0].Value = value.TableName;
            parameters[1].Value = value.PrimaryKey;
            parameters[2].Value = value.OrderStr;
            parameters[3].Value = value.PageIndex;
            parameters[4].Value = value.PageSize;
            parameters[5].Value = value.QueryFieldName;
            parameters[6].Value = value.QueryCondition;
            parameters[7].Value = value.Group;

            try
            {
                return SqlHelper.GetDataFormDataSet(CommandType.StoredProcedure, "SP_Pagination", parameters);
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        /// 执行语句，获取第一行第一列
        /// </summary>
        /// <param name="strSql"></param>
        /// <returns></returns>
        public int ExecuteScalar(string strSql)
        {
            return int.Parse(SqlHelper.ExecuteScalar(CommandType.Text, strSql, null).ToString());
        }
    }
}
